Android ile .NET Web Servisten List Tipindeki Veriyi Alma
Merhaba arkadaşlar ;
Android ile Web Servisten dönen list tipindeki veriyi alamıyorum .Web Servis sorunsuz çalışıyor.
[code]
public class ProductBusiness
{
public int Id { get; set; }
public string Name { get; set; }
public byte[] Image { get; set; }
}
public class ProductBusinessService : System.Web.Services.WebService
{
HealthyFoodEntities db;
public ProductBusinessService()
{
db = new HealthyFoodEntities();
}
[WebMethod]
public List<ProductBusiness> getProduct()
{
var query = from x in db.Products
select new ProductBusiness
{
Id= x.Id,
Image = x.Picture,
Name = x.ProductName
};
return query.ToList();
}
[/code]
Bu kodlar .NET tarafında veritabanından veri çekmek için yazdığım kodlar ve sorunsuz çalışıyor.Android tarafında da şu şekilde verilere erişmeye çalışıyorum.
[code]
public class Product {
private int id;
private String name;
private byte[] image;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public class Main extends ActionBarActivity {
List<Product> myList;
TextView textView;
Button button;
public static final String NAMESPACE="http://tempuri.org/";
public static final String SOAP_ACTION="http://tempuri.org/getProduct";
public static final String URL="http://192.168.1.31/HealthyNutrition/ProductBusinessService.asmx";
public static final String METHOD_NAME="getProduct";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.textView1);
button = (Button) findViewById(R.id.button1);
myList = new ArrayList<Product>();
public void onClick(View v)
{
Thread nt=new Thread(){
public void run(){
SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE transport=new HttpTransportSE(URL);
try {
transport.call(SOAP_ACTION, envelope);
SoapObject response=(SoapObject) envelope.getResponse();
final int intPropertyCount = response.getPropertyCount();
/* for (int i = 0; i < intPropertyCount; i++) {
SoapObject responseChild = (SoapObject) response.getProperty(i);
Product product = new Product();
if(responseChild.hasProperty("Id")){
product.setId(responseChild.getPropertyAsString("Id"));
}
if(responseChild.hasProperty("Name")){
product.setName(responseChild.getPropertyAsString("Name"));
}
if(responseChild.hasProperty("Image")){
product.setImage(responseChild.getPropertyAsString("Image"));
}
myList.add(product);
}*/
textView.setText(intPropertyCount);
} catch (HttpResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
nt.start();
}
}
}
[/code]
Property count tu bile alamıyorum.Uygulama durduruluyor.Nasıl yapabilirim?